﻿#ifndef BUTTON_H
#define BUTTON_H

#include <QGraphicsObject>
#include <QGraphicsScene>
#include <QPixmap>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>

class Button : public QGraphicsObject
{
    Q_OBJECT
public:
    Button(QGraphicsScene* scene, QString text);
    ~Button();

protected:
    QRectF boundingRect() const;
    void paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option,
               QWidget *widget);
    void drawFace();

    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);

    // 不参与碰撞检测
    bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const;

private:
    void initAnimation();

signals:
    void clicked();

private:
    QGraphicsScene* m_scene;
    QPixmap* m_face;
    QString m_text;
    QPropertyAnimation* m_selectAnimation;
    QPropertyAnimation* m_leaveAnimation;
    QPropertyAnimation* m_pressAnimation;
    QPropertyAnimation* m_backAnimation;
    QSequentialAnimationGroup* Button_Press;
};

#endif // BUTTON_H
